package CloudStorage;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class File
{
    int id;
    int ownerId;
    String name;
    String status;
    float value;
    int downloads;
    String category;
    String description;
    String datePublished;

    public int getID() { return id; }
    public int getOwnerId() { return ownerId; }
    public String getStatus() { return status; }
    public float getValue() { return value; }
    public int getDownloads() { return downloads; }
    public String getCategory() { return category; }
    public String getDescription() { return description; }
    public String getDatePublished() { return datePublished; }

   public void setDescription (String description) { this.description = description; }

    /* Full parameter constructor for data extraction */

    public File ( int id, int ownerId, String name, String status, float value, int downloads, String category, String description, String datePublished )
    {
        this.id = id;
        this.ownerId = ownerId;
        this.name = name;
        this.status = status;
        this.value = value;
        this.downloads = downloads;
        this.category = category;
        this.description = description;
        this.datePublished = datePublished;
    }


    public File ( int ownerId, String name, String status, Float value, int downloads, String category, String description )
    {
        this.ownerId = ownerId;
        this.name = name;
        this.status = status;
        this.value = value.floatValue();
        this.downloads = downloads;
        this.category = category;
        this.description = description;
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date = new java.util.Date();
        this.datePublished = dateFormat.format(date);
    }

    /* Public File with zero downloads constructor */

    public File ( int ownerId, String name, String status, Float value, String category, String description )
    {
        this.ownerId = ownerId;
        this.name = name;
        this.status = status;
        this.value = value.floatValue();
        this.downloads = 0;
        this.category = category;
        this.description = description;
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date = new java.util.Date();
        this.datePublished = dateFormat.format(date);
    }


    /* Private File Constructor with zero downloads*/

    public File ( int ownerId, String name, String category, String description )
    {
        this.ownerId = ownerId;
        this.name = name;
        this.status = "private";
        this.value = 0;
        this.downloads = 0;
        this.category = category;
        this.description = description;
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date = new java.util.Date();
        this.datePublished = dateFormat.format(date);
    }

    public String getName()
    {
        for ( int i = 0; i < name.length(); i++ )
        {
            if ( name.charAt(i) == '/' )
            {
                return name.substring(i + 1, name.length());
            }
        }

        return name;
    }

    public String getFullName() { return name; }

    public String getFolder()
    {
        for ( int i = 0; i < name.length(); i++ )
        {
            if ( name.charAt(i) == '/' )
            {
                return name.substring(0, i);
            }
        }

        return "";
    }

    public void ChangeFolder(String newFolder)
    {
        int index = this.name.indexOf('/');
        String filename = name.substring(index);
        this.name = newFolder + filename;
    }

    @Override
    public String toString()
    {
        return String.valueOf(id);
    }
}
